package main

import (
	"flag"
	"gitee.com/baal1990/gitee.com/baal1990/pkg/crypto"
	"log"
	"strings"
)

var (
	Digest     = make(map[string]crypto.MessageDigest)
	CryptoType = ""
	Data       = ""
)

func initCrypto() {
	Digest["sm3"] = crypto.SM3{}
}

func main() {
	flag.StringVar(&CryptoType, "type", "", "sm3")
	flag.StringVar(&Data, "data", "", "")
	flag.Parse()
	initCrypto()
	CryptoType = strings.ToLower(CryptoType)
	crypto, ok := Digest[CryptoType]
	if !ok {
		log.Printf("invalid type, [%s]\n", CryptoType)
		log.Println("run --help")
		return
	}
	digest, err := crypto.Sum([]byte(Data))
	if err != nil {
		log.Printf("%s fail, %v\n", CryptoType, err)
		return
	}
	log.Printf("raw    = [%s]\n", Data)
	log.Printf("digest = [%s]\n", digest)
}
